package com.fau.ss.util;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

public class DateUtil {
	
	public static String getDate(Boolean time, Integer day){
		Calendar currentDate = new GregorianCalendar();
		String date = "";
		if(time){
			currentDate.set(Calendar.HOUR_OF_DAY, 0);
			currentDate.set(Calendar.MINUTE, 0);
			currentDate.set(Calendar.SECOND, 0);
		}else {
			currentDate.set(Calendar.HOUR_OF_DAY, 23);
			currentDate.set(Calendar.MINUTE, 59);
			currentDate.set(Calendar.SECOND, 59);
		}
		
		if(null != day) currentDate.add(Calendar.DATE, day);
		
		date = DateFormatUtils.format(currentDate.getTime(), "yyyyMMddHHmmss");
		return date;
	}
	
	public static Date getDates(Boolean time, Integer day){
		Calendar currentDate = new GregorianCalendar();
		if(time){
			currentDate.set(Calendar.HOUR_OF_DAY, 0);
			currentDate.set(Calendar.MINUTE, 0);
			currentDate.set(Calendar.SECOND, 0);
		}else {
			currentDate.set(Calendar.HOUR_OF_DAY, 23);
			currentDate.set(Calendar.MINUTE, 59);
			currentDate.set(Calendar.SECOND, 59);
		}
		
		if(null != day) currentDate.add(Calendar.DATE, day);
		
		return currentDate.getTime();
	}
	
	public static Date getDate(Integer day){
		Calendar currentDate = new GregorianCalendar();
		currentDate.set(Calendar.HOUR_OF_DAY, 23);
		currentDate.set(Calendar.MINUTE, 59);
		currentDate.set(Calendar.SECOND, 59);
		
		if(null != day) currentDate.add(Calendar.DATE, day);
		
		return currentDate.getTime();
	}
	
	/**
	 * @desc 将字符串格式日期转换为日期类型
	 * @param strDate 字符串格式日期
	 * @return
	 * @author kangyj
	 * @datetime 2014年11月17日,下午5:04:28
	 */
	public static Date getDate(String strDate) {
		Date date = null;
		try {
			date = DateUtils.parseDate(strDate, "yyyy-MM");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	
	
	
	
}
